$.extend({
    moneyFormat: function(number){
        var num=0;
        if(number){
            num = parseFloat(number).toFixed(2);
            num = parseFloat(num)
            num = num.toLocaleString();
        }
        return `¥ ${num}`;
    },
    mySwalConfirm: function (text = "", cb = function () {

    }, title, className) {
        swal({
            title: title ? title : "操作提示",
            text: text ? text : '确认吗？',
            type: "warning",
            customClass: className ? className : undefined,
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        }, function () {
            cb();
        });
    },
    mySwalWarn: function (text = "", cb = function () {
        
    }) {
        swal({
            title: "操作提示",
            text: text ? text : '操作不正确？',
            type: "warning",
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            closeOnConfirm: true
        }, function () {
            cb();
        });
    },
    buildMenu: function (menuList) {
        $('.createMenu').remove()
        menuList.map(o => {
            let menuOne = buildMenuPri(o);
            $('#side-menu').append(menuOne);
        })
    }
});

function buildMenuPri(data) {
    let menuOne = $('<li class="createMenu"/>');
    if (data) {
        let menuOneA = $(`<a href="${data.url}" class="myMenu"/>`);
        let menuOneI = $('<i/>');
        if (data.icon) {
            menuOneI.addClass(`fa fa-${data.icon}`);
        } else {
            menuOneI.addClass('fa fa-gear');
        }
        let menuOneText = $('<span/>');
        menuOneText.addClass('nav-label');
        menuOneText.text(data.name);
        menuOneA.append(menuOneI);
        menuOneA.append(menuOneText);
        if (data.list != null) {
            menuOneA.append('<span class="fa arrow"></span>');
            menuOne.append(menuOneA)
            let menuOneUl = $('<ul class="nav nav-second-level"/>');
            data.list.map(subMenu => {
                menuOneUl.append(buildMenu2Pri(subMenu));
            });
            menuOne.append(menuOneUl)
        } else {
            menuOne.append(menuOneA)
        }
    }
    return menuOne;
}

function buildMenu2Pri(data) {
    let menuTwoLi = $('<li/>');
    let menuTowA = $(`<a href="#" data-menuid="${data.menuId}" data-url="${data.url}" data-frame="${data.hasFrame}" data-header="true" class="myMenu"/>`);
    menuTowA.text(data.name);
    menuTwoLi.append(menuTowA)
    return menuTwoLi;
}

/*自定义JQUERY验证*/
/*保留2位小数*/
jQuery.validator.addMethod("toDecimal2", function (value, element) {
    var returnVal = true;
    inputZ = value;
    var ArrMen = inputZ.split(".");    //截取字符串
    if (ArrMen.length == 2) {
        if (ArrMen[1].length > 2) {    //判断小数点后面的字符串长度
            returnVal = false;
            return false;
        }
    }
    return returnVal;
}, "小数点后最多为两位");